1. Field of the Invention
This invention relates to a method and system for memory management in virtual environments, and more particularly to a virtual SWAP for Virtual Environments (VE), such as Parallels Containers.
2. Description of the Related Art
Virtualization in computer systems presents some challenges with regard to memory management among isolated virtual environments. In Containerized environments all Containers use the same virtual memory. Each Container can consume the entire memory. Therefore, the amount of memory used by the Containers needs to be limited.
Modern OS-es use two types of memory—random access memory or RAM (fast direct accesses, but limited in quantity) and SWAP file (slow, not directly accessible but almost unlimited). Typically, if a process requires memory, the OS allocates some memory from the RAM. If no free RAM is available, some of the process-related data is moved from the RAM to a SWAP file. The direct access from processes to this RAM is marked to notify the OS that the data is moved to SWAP file and the RAM can be used for storing data from other processes.
A conventional use of a memory SWAP file is illustrated in FIG. 1. A page request is received in step 110. In step 112, process determines if an RSS (resident set size, a number of pages currently residing in RAM) exceeds the RAM size. If the RAM has some free space, the number of currently residing pages is increased in step 114 and page is allocated in step 118. Then the memory allocation is finished in step 120.
If, in step 112, it is determined that the RAM does not have any free space, it is checked if SWAP file has not reached the limit (see step 116). If the SWAP file is at the limit, the system is out of memory (step 128) and the number of resident pages in SWAP file is increased in step 126. If, in step 116, the SWAP file is under the limit, the page is found in LRU (least recently used set) in step 122 and the page is written to SWAP file in step 124, then the number of resident pages is increased in step 126.
When the process attempt to access the data that is currently resides in SWAP file, the OS this data back to the RAM and sets up the direct access to this data again. Hosting of the SWAP file is described in http:**kerneltrap.org/node/3660.
However, none of the memory management systems that limit memory consumption work with Containers in virtual execution environment to manage memory on a per-Container basis. Accordingly, there is a need for a system and method that limit the virtual memory usage by the Containers using SWAP file.